<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef">
      <template #create_time="{ record }">
        {{ tool.dateFormat(record.create_time, 'yyyy-MM-dd hh:mm:ss', '-') }}
      </template>
    </ma-crud>
  </div>
</template>
<script setup>
import { ref, reactive } from 'vue'
import infoClass from '@/api/info/infoClass'
import { Message } from '@arco-design/web-vue'
import tool from '@/utils/tool'
import * as common from '@/utils/common'

const crudRef = ref()


const numberOperation = (newValue, id, numberName) => {
  infoClass.numberOperation({ id, numberName, numberValue: newValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}

const switchStatus = (statusValue, id, statusName) => {
  infoClass.changeStatus({ id, statusName, statusValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}


const options = reactive({
  id: 'us_info_class',
  rowSelection: {
    showCheckedAll: true
  },
  bordered:{ wrapper: true, cell: true },
  pk: 'id',
  operationColumn: true,
  operationColumnWidth: 160,
  formOption: {
    viewType: 'modal',
    width: 600
  },
  api: infoClass.getList,
  recycleApi: infoClass.getRecycleList,
  add: {
    show: true,
    api: infoClass.save,
    auth: ['info:class:save']
  },
  edit: {
    show: true,
    api: infoClass.update,
    auth: ['info:class:update']
  },
  delete: {
    show: true,
    api: infoClass.deletes,
    auth: ['info:class:delete'],
    realApi: infoClass.realDeletes,
    realAuth: ['info:class:realDeletes']
  },
  recovery: {
    show: true,
    api: infoClass.recoverys,
    auth: ['info:class:recovery']
  }
})

const columns = reactive([
  {
    title: "ID",
    dataIndex: "id",
    width:80,
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    commonRules: {
      required: true,
      message: "请输入ID"
    }
  },
  {
    title: "名称",
    dataIndex: "name",
    width:220,
    formType: "input",
    search: true
  },

  {
    title: "排序",
    dataIndex: "display_order",
    formType: "input-number",
    min:1,
    precision: 0,

  },
  {
    title: "创建者",
    dataIndex: "created_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "更新者",
    dataIndex: "updated_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "状态",
    dataIndex: "status",
    formType: "radio",
    search: true,
    dict: {
      name: "data_status",
      props: {
        label: "title",
        value: "key"
      },
      translation: true
    },
    addDefaultValue: '1',
  },
  {
    title: "创建时间",
    dataIndex: "create_time",
    width:180,
    formType: "input",
    search: true,
    addDisplay: false,
    editDisplay: false
  },
  {
    title: "更新时间",
    dataIndex: "update_time",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  }
])
</script>
<script> export default { name: 'info:class' } </script>